package com.fh.module_main.ui.activity

import com.alibaba.android.arouter.facade.annotation.Route
import com.fh.lib_base.base.AppManager
import com.fh.lib_base.base.BaseActivity
import com.fh.lib_base.config.AppConstants
import com.fh.module_main.R
import com.fh.module_main.BR
import com.fh.module_main.databinding.MainActivityMainBinding
import com.fh.module_main.viewmodel.MainViewModel

@Route(path = AppConstants.Router.Main.MAIN_ACTIVITY)
class MainActivity: BaseActivity<MainActivityMainBinding, MainViewModel>() {

    //用于记录按下回退键时间
    private var backPressTime = 0L
    companion object {
        const val MAIN_FRAGMENT = "fragment"
        const val MAIN_BUNDLE = "bundle"
    }

    override fun initContentView(): Int {
        return R.layout.main_activity_main
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }

    override fun useBaseLayout(): Boolean {
        return false
    }
    override fun initViewObservable() {

    }
    override fun initData() {

    }
    override fun onBackPressedSupport() {
        if (supportFragmentManager.backStackEntryCount > 0) {
            supportFragmentManager.popBackStack()
        } else {
            processBackPressed()
        }
    }
    private fun processBackPressed() {
        val now = System.currentTimeMillis()
        if (now - backPressTime > 2000) {
            showNormalToast(getString(R.string.press_again_to_exit))
            backPressTime = now
        } else {
            AppManager.instance.appExit()
        }
    }
}